<template>
	<view style="padding:16rpx 30rpx;">
		<view class="uni-flex custom-card" v-for="(item,index) in list" :key="index" >
			<view class="con-left" @click="setRead(index)">
				<view class="time"><text>{{item.pushTime}}</text></view>
				<view class="notice-con" :class="{readed:(item.status == 1? true:false)}">{{item.content}}</view>
			</view>
			<view class="con-right" v-if="item.status == 0? true:false"><uni-icons type="smallcircle-filled" size="10" color="#FF5A5A"></uni-icons></view>
		</view>		
		<!-- <view class="uni-flex custom-card">
			<view class="con-left">
				<view class="time"><text>2023-05-14  09:00:00</text></view>
				<view class="notice-con">消息提醒：您关注的“水产养殖”专题，有一个农户发起了求助，立即查看详细动态</view>
			</view>
			<view class="con-right" v-if="true"><uni-icons type="smallcircle-filled" size="6" color="#FF5A5A"></uni-icons></view>
		</view>
		<view class="uni-flex custom-card">
			<view class="con-left">
				<view class="time"><text>2023-05-14  09:00:00</text></view>
				<view class="notice-con readed">消息提醒：您发布的“水产养殖”农户求助，收到了一条新的回复，更多信息点此查看</view>
			</view>
			<view class="con-right" v-if="false"><uni-icons type="smallcircle-filled" size="6" color="#FF5A5A"></uni-icons></view>
		</view> -->
	</view>
</template>

<script>
	import {queryMySiteMessageList,readSiteMessage} from "@/api/user.js"
	export default {
		data() {
			return {
				list:[],
				page: 1,
				maxpage: 0,
				showLoadMore: false,
			};
		},
		onLoad(){
		this.initData();
		},
		onPullDownRefresh() {
			console.log('onPullDownRefresh');
			this.initData();
		},
		onReachBottom() {
			console.log("onReachBottom");
			console.log("page", this.page, this.maxpage)
			if (this.page == this.maxpage) {
				this.showLoadMore = false;
				return
			}
			this.showLoadMore = true;
			this.page++;
			this.queryMySiteMessageList({ //参数
				"condition": null,
				"pageNum": this.page,
				"pageSize": 10
			});
		},
		methods:{
			async queryMySiteMessageList(options){
				const res = await queryMySiteMessageList(options);
				if(res.returnObj){
					this.maxpage = res.returnObj.navigateLastPage;
					this.list = this.list.concat(res.returnObj.list);
					this.showLoadMore = false;
				}	
			},
			initData() {
				this.page = 1;
				this.list = [];
				this.showLoadMore = true;
				this.queryMySiteMessageList({ //参数
					"condition": null,
					"pageNum": this.page,
					"pageSize": 10
				});
				uni.stopPullDownRefresh();
			},
			setRead(index){				
				readSiteMessage(this.list[index].id).then((res)=>{
					if(res.success){
						this.list[index].status = 1
					}
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
